import Mock from 'mockjs'
import PERSONS from './fakeData/PERSONS.js' // '../../../public/fakeData/PERSONS.js'

const Random = Mock.Random

Random.extend({
  personList: function(data) {
    let list = PERSONS.data
    return this.pick(list)
  }
})

const targetPersons = function (query) {
  let key = Object.entries(query)[0][0]
  let value = Object.entries(query)[0][1]
  let targets = PERSONS.data.filter((item) => {
    return item[key] === value
  })
  return targets
}

export function getPersonsMock(Mock, url, query) {
  return Mock.mock({
    code: 0,
    msg: '',
    data: {
      page: `${query.pageIndex}`,
      limit: `${query.pageSize}`,
      total: 50,
      [`list|${query.pageSize}`]: [ '@personList' ],
      // [
      //   {
      //     'rylb|3-6': '@cword',
      //     'zjhm': '@cword',
      //     'xm|2-4': '@cword',
      //     'mz|2-3': '@cword',
      //     'hjd|5-15': '@cword',
      //     'xzd|5-15': '@cword',
      //     'rybq|5-8': '@cword'
      //   }
      // ],
      colData: PERSONS.colData.map((item) => {
        return {
          ...item,
          filterable: true,
          necessary: true,
          type: 'input'
        }
      })
      // [
      //   { prop: 'rylb', label: '人员类别', filterable: true, necessary: true, type: 'input' },,
      //   // { prop: 'lx', label: '类型', filterable: true, necessary: true, type: 'Options', direct: '' },
      //   // { prop: 'sj', label: '时间', filterable: true, necessary: true, type: 'DateTime' }
      // ]
    } 
  }) 
} 

export function findPersonsMock(Mock, url, query) {
  console.log('mockfineperson', query)
  return Mock.mock({
    code: 0,
    msg: '',
    data: {
      'list': targetPersons(query),
      // 'list|1': [ ...targetPersons(query) ],
      col: {
        rylb: '人员类别',
        zjhm: '证件号码',
        xm: '姓名',
        mz: '民族',
        hjd: '户籍地',
        xzd: '现住地',
        rybq: '人员标签'
      }
    } 
  }) 
}